package com.owen.server.impl;

import com.owen.dao.OrderDao;
import com.owen.pojo.Order;
import com.owen.server.OrderServer;
import com.owen.utils.RedisUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class OrderServerImpl implements OrderServer {

    @Autowired
    private OrderDao orderDao;

    @Autowired
    private RedisUtil redisUil;

    @Override
    public List<Order> findAll() {
        List<Order> findOrder = (List<Order>) redisUil.get("findOrder");
        if (findOrder == null) {
            findOrder = orderDao.findAll();
            redisUil.set("findOrder", findOrder);
        }
        return findOrder;
    }

    @Override
    public List<Order> findByOrder(Order order) {
        return orderDao.findByOrder(order);
    }

    @Override
    public Order findById(Integer id) {
        return orderDao.findById(id);
    }

    @Override
    public Integer updateOrder(Integer id) {
        Integer integer = orderDao.updateOrder(id);
        redisUil.del("findOrder");
        return integer;
    }

    @Override
    public Integer deleteBatch(Integer[] ids) {
        Integer integer = orderDao.deleteBatch(ids);
        redisUil.del("findOrder");
        return integer;
    }

}